package com.googlecode.microanalyst.palette.figure;

import org.eclipse.draw2d.ImageFigure;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

import com.googlecode.microanalyst.palette.plugin.MicroanalystPalettePlugin;

public class Images {

	private static final String DATASET_NAME = "../model/icons/dataset8.gif"; //$NON-NLS-1$
	public static final ImageDescriptor DATASET;
	public static final ImageFigure DATASET_FIGURE;
	public static final Image DATASET_IMAGE;

	private static final String OUTPUT_NAME = "../model/icons/output8.gif"; //$NON-NLS-1$
	public static final ImageDescriptor OUTPUT;
	public static final ImageFigure OUTPUT_FIGURE;
	public static final Image OUTPUT_IMAGE;

	static {
		DATASET = createAndCache(DATASET_NAME);
		DATASET_IMAGE = Images.get(DATASET_NAME);
		DATASET_FIGURE = new ImageFigure(DATASET_IMAGE);
		OUTPUT = createAndCache(OUTPUT_NAME);
		OUTPUT_IMAGE = Images.get(OUTPUT_NAME);
		OUTPUT_FIGURE = new ImageFigure(OUTPUT_IMAGE);
	}

	private static ImageDescriptor createDescriptor(String filename) {
		return ImageDescriptor.createFromFile(Images.class, filename);
	}

	public static Image get(String imageName) {
		final MicroanalystPalettePlugin plugin = MicroanalystPalettePlugin
				.getDefault();
		final ImageRegistry imageRegistry = plugin.getImageRegistry();
		return imageRegistry.get(imageName);
	}

	private static ImageDescriptor createAndCache(String imageName) {
		ImageDescriptor result = createDescriptor(imageName);
		MicroanalystPalettePlugin plugin = MicroanalystPalettePlugin
				.getDefault();
		ImageRegistry imageRegistry = plugin.getImageRegistry();
		imageRegistry.put(imageName, result);
		return result;
	}

}
